<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;

class BaseRequest extends FormRequest
{
    /**
     * @param Validator $validator
     */
    public function withValidator($validator)
    {
        if (method_exists($this, 'after')) {
            $validator->after(function (Validator $validator) {
                if (!$validator->errors()->count()) {
                    $result = $this->after();
                    if (is_array($result)) {
                        $validator->errors()->add($result[0], $result[1]);
                        return ['xx'];
                    }
                }
            });
        }
    }
}
